import React from 'react';
import {
  HashRouter,
  Route,
  Switch,
} from 'react-router-dom';

// 路由配置
const routerConfig = [
  {
    path: '/',
    component: HomePage,
    auth: false,
  }, {
    path: '/home',
    component: HomePage,
    auth: true, // 表示必须登录才能访问
  }, {
    path: '/login',
    component: LoginPage,
  }, {
    path: '/404',
    component: ErrorPage
  }
];

class RouterTab extends React.Component {
  render() {
    return (
      <HashRouter>
        <Switch>
          <RouteGenerator config={routerConfig} />
        </Switch>
      </HashRouter>
    );
  }
}

class RouterGenerator extends React.Coponent {
  // 在这里定义限制路由的逻辑（业务场景1）
  render() {
    const routeConf = this.props.config;
    routeConf.map((conf) => {
      if (conf.auth) // 判断该路由是否满足渲染条件
      {
        if (login) // 判断当前有没有登录
        {
          retrun <Route path = { conf.path } component = { conf.component } exact = { conf.exact ? true : false } />
        }
      } else {
        retrun <Route path = { conf.path } component = { conf.component } exact = { conf.exact ? true : false } />
       }
    });
  }
}